import Ember from 'ember';
import BaseBusiness from '../base-business';
import Pagination from '../pagination';
const {
    sexType,
    staffStatus,
    hireType,
    educationLevel,
    maritalStatus,
    relationType,
    nationality,
    nativePlace
} = Constants;

export default BaseBusiness.extend(Pagination, {
    header_title: '护工人员信息',
    queryParams: {
        id: {
            refreshModel: true
        }
    },
    role_par: null,
    model() {
        return {};
    },
    setupController: function(controller, model) {
        this._super(controller, model);
        controller.set("operateFlag", null);
        controller.set("editModel", null);
        controller.set("sysPassWord", '');
        controller.set("appPassWord", '');
        console.log("operateFlagid " + this.getCurrentController().get('id'));
        if (this.getCurrentController().get('id') !== 'null') {
            console.log("operateFlag " + 'ttt');
            this.store.findRecord("user", this.getCurrentController().get('id')).then(function(staff) {
                controller.set("staff", staff);
                //staff.set('privilege',_self.get("privilege"));
                // staff.set('org',_self.get("org"));
                controller.set('hireType', staff.get("hireType"));
                controller.set("role", staff.get('role'));
                controller.set("hireType", staff.get('hireType'));
                controller.set("staffSex", staff.get('staffSex'));
                controller.set("staffContactRelation", staff.get('staffContactRelation'));
                controller.set("staffEducation", staff.get('staffEducation'));
                controller.set("operateFlag", "edit");
                controller.set("header_title", "机构信息");
                console.log("operateFlag " + 'edit');
            });
        } else {
            let model = this.get("store").createRecord('user', {});
            //controller.set("staff", model);
            controller.set("staff", model);
            controller.set("staffModel", model);
            controller.set("operateFlag", "add");
            controller.set("header_title", "添加机构");
            console.log("operateFlag " + 'add');
            var curUser = this.get('global_curStatus').getUser();
            var _self = this;
            console.log("user  " + curUser.get('id'));
            this.store.findRecord('user', curUser.get('id')).then(function(user) {
                console.log("id  " + user.get('org').get('id'));
                _self.store.findRecord('organization', user.get('org').get('id')).then(function(org) {
                    model.set('org', org);
                });
            });
        }
        this.store.query("role", {}).then(function(roleList) {
            controller.set("roleList", roleList);
            console.log('doQuery roleList', roleList);
        });
    },

});
